Skip to content

feat(cells) Make organization-create work in control silo #115238

Open
markstory wants to merge 2 commits intomasterfrom
feat-control-org-create
Open

feat(cells) Make organization-create work in control silo #115238
markstory wants to merge 2 commits intomasterfrom
feat-control-org-create

Conversation

@markstory
Copy link
Copy Markdown
Member

With all the RPC refactoring done, we can make POST /organizations work in control silo. Having this endpoint work in both cell & control silo modes is necessary so that we can update internal clients incrementally.

These changes also add support for dataStorageLocation with locality -> cell resolution which is required for control based provisioning.

Refs INFRENG-186

markstory added 2 commits May 8, 2026 17:12
With all the RPC refactoring done, we can make `POST /organizations`
work in control silo. Having this endpoint work in both cell & control
silo modes is necessary so that we can update internal clients
incrementally.

These changes also add support for `dataStorageLocation` with locality
-> cell resolution which is required for control based provisioning.

Refs INFRENG-186
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 8, 2026

INFRENG-186

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 8, 2026
@markstory markstory marked this pull request as ready for review May 11, 2026 14:03
@markstory markstory requested a review from a team as a code owner May 11, 2026 14:03
@markstory markstory requested a review from a team May 11, 2026 14:05
Comment on lines +446 to +447

return Response(org_data, status=201)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Due to replica lag, reading a newly created organization for serialization can fail, resulting in an empty response body on a successful 201 creation.
Severity: MEDIUM

Suggested Fix

To ensure the newly created organization is found, perform the read for serialization from the primary database. This can be achieved by forcing the read query within organization_service.serialize_organization to use the primary database, for example by wrapping the call in a block that directs reads to the write replica.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/sentry/core/endpoints/organization_index.py#L446-L447

Potential issue: The organization creation endpoint can return an empty response body
with a `201` status code due to replica lag. The organization is provisioned on the
primary database via an RPC. Immediately after, the
`organization_service.serialize_organization` function attempts to fetch this new
organization for the response body. This read operation can be directed to a replica
database which may not have received the new data yet. This causes the serialization
function to return `None`, leading to an empty response body, which violates the API
contract expecting the new organization's data.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b22ff7d. Configure here.

locality_name = settings.SENTRY_MONOLITH_REGION

if locality_name is not None:
attrs["cell_name"] = get_new_org_cell_for_locality(locality_name).name
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unhandled CellResolutionError in validate causes 500 error

Medium Severity

get_new_org_cell_for_locality in the validate method can raise CellResolutionError, which is not a DRF ValidationError. DRF's is_valid() only catches ValidationError, so this would bubble up as an unhandled 500 error. The field-level validate_dataStorageLocation properly catches CellResolutionError and converts it, but validate does not — both for user-provided values (where new_org_cell could reference a nonexistent cell) and for the settings.SENTRY_MONOLITH_REGION default (which bypasses validate_dataStorageLocation entirely and is not validated for existence, MULTI_TENANT category, or visibility).

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b22ff7d. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant